import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';
const { getFamilyList } = require('../../../api/personal')
let app =  getApp();
Page({
  data:{
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '家庭成员', //导航栏 中间的标题
      white: false, // 是就显示白的，不是就显示黑的。
      bgColor:'#b7eade'
    },
    // 导航头的高度
    height: app.globalData.height * 2,
    familyList:[
      {
          //child_name是控制端给被控制端的备注,child_xcx_openID是被控制端的xcxopenID
          "child_name": "大妈",
          "child_xcx_openID": "nancy",
          "iD": 2
      },
      {
          "child_name": "大爷",
          "child_xcx_openID": "hank",
          "iD": 4
      }
  ]
  },
  onLoad(){
    let that = this
    wx.getStorage({
      key:'phone',
      fail(err){
        Dialog.alert({
          title: '暂无手机号码',
          message: '使用家庭账号功能，需要设置手机号码'
        })
          .then(() => {
            wx.navigateTo({url:'../phone/phone'})
          })
      }
    })
    getFamilyList.request()
    .then(res=>{
      const { State, List } = res
      if(State){
        that.setData({familyList:List})
      }
    })
  },
  onClose(event) {
    const { position, instance } = event.detail;
    switch (position) {
      case 'left':
      case 'cell':
        instance.close();
        break;
      case 'right':
        Dialog.confirm({
          message: '确定删除吗？',
        }).then(() => {
          instance.close();
        });
        break;
    }
  },
  toAddNewFamiy(){
    wx.navigateTo({
      url:'addFamily/index'
    })
  },
  delete(){
    Dialog.confirm({
      title: '提示',
      message: '是否确定删除家庭成员',
    })
      .then(() => {
        // on confirm
      })
      .catch(() => {
        // on cancel
      });
  },
  toFamilyInfo(e){
    let openid = e.currentTarget.dataset.openid
    wx.navigateTo({
      url:'familyInfo/index?openid='+openid
    })
  },
  addNewFamily(){
    wx.navigateTo({
      url:'addFamily/index'
    })
  }
});